using System;
using System.Collections.Generic;
using System.Linq;
namespace GIFT_SHOP_MVC.Models
{
    partial class GiftShop_LinQDataContext
    {
        public List<TheLoai> GetCategories()
        {
            return TheLoais.ToList();
        }

        public List<NhaCungCap> GetSuppliers()
        {
            return NhaCungCaps.ToList();
        }

        public NhaCungCap GetSupplierById(int id)
        {
            return NhaCungCaps.Single(s=>s.MaNhaCungCap == id);
        }

        public List<TinhTrang_SP> GetProductStatus()
        {
            return TinhTrang_SPs.Where(stt=>stt.Ma_TT != 2).ToList();
        }

        public List<PhieuNhap> GetImports()
        {
            return PhieuNhaps.ToList();
        }

        public List<CT_PhieuNhap> GetImportById(int id)
        {
            return CT_PhieuNhaps.Where(d => d.MaPhieuNhap == id).ToList();
        }

        public List<PhieuXuat> GetBill()
        {
            return PhieuXuats.ToList();
        }

        public List<CT_PhieuXuat> GetBillById(int id)
        {
            return CT_PhieuXuats.Where(d => d.MaPhieuXuat == id).ToList();
        }

        public List<SanPham> GetProductByIdCategory(int id)
        {
            return SanPhams.Where(sp => sp.MaTheLoai == id).ToList();
        }

        public List<SanPham> GetProduct()
        {
            return SanPhams.OrderByDescending(p=>p.NgayNhap).ToList();
        }

        public List<SanPham> GetProductNew()
        {
            var list = SanPhams.OrderByDescending(p=>p.NgayNhap).Take(6).ToList();
            return list;
        }

        public SanPham GetProductById(int id)
        {
            return SanPhams.Single(sp => sp.MaSanPham == id);
        }

        public User GetUserById(int id)
        {
            return Users.Single(u => u.MaUser == id);
        }

        public List<User> GetUsers()
        {
            return Users.Where(u => u.Admin == false).ToList();
        }

        public List<TinhTrang_User> GetUserStatus()
        {
            return TinhTrang_Users.ToList();
        }
    }
}
